home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / ripdump.c < prev    next >
C/C++ Source or Header  |  1991-02-25  |  1KB  |  61 lines

  1. /* @(#) $Header: ripdump.c,v 1.2 91/02/24 20:17:36 deyke Exp $ */
  2.  
  3. /* RIP packet tracing
  4.  * Copyright 1991 Phil Karn, KA9Q
  5.  */
  6. #include "global.h"
  7. #include "mbuf.h"
  8. #include "netuser.h"
  9. #include "timer.h"
  10. #include "rip.h"
  11. #include "trace.h"
  12.  
  13. void
  14. rip_dump(fp,bpp)
  15. FILE *fp;
  16. struct mbuf **bpp;
  17. {
  18.     struct rip_route entry;
  19.     int i;
  20.     int cmd,version;
  21.     int16 len;
  22.  
  23.     fprintf(fp,"RIP: ");
  24.     cmd = PULLCHAR(bpp);
  25.     version = PULLCHAR(bpp);
  26.     switch(cmd){
  27.     case RIPCMD_REQUEST:
  28.         fprintf(fp,"REQUEST");
  29.         break;
  30.     case RIPCMD_RESPONSE:
  31.         fprintf(fp,"RESPONSE");
  32.         break;
  33.     default:
  34.         fprintf(fp," cmd %u",cmd);
  35.         break;
  36.     }
  37.  
  38.     pull16(bpp);    /* remove one word of padding */
  39.  
  40.     len = len_p(*bpp);
  41.     fprintf(fp," vers %u entries %u:\n",version,len / RIPROUTE);
  42.  
  43.     i = 0;
  44.     while(len >= RIPROUTE){
  45.         /* Pull an entry off the packet */
  46.         pullentry(&entry,bpp);
  47.         len -= RIPROUTE;
  48.  
  49.         if(entry.addr_fam != RIP_IPFAM) {
  50.             /* Skip non-IP addresses */
  51.             continue;
  52.         }
  53.         fprintf(fp,"%-16s%-3u ",inet_ntoa(entry.target),entry.metric);
  54.         if((++i % 3) == 0){
  55.             putc('\n',fp);
  56.         }
  57.     }
  58.     if((i % 3) != 0)
  59.         putc('\n',fp);
  60. }
  61.